package org.example.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.domain.Book;
import org.example.domain.BookContent;

import java.util.List;

@Mapper
public interface BookDao extends BaseMapper<Book> {
    @Select("select type from book_type where book_id=#{bookId}")
    List<String> getBookType(int bookId);
    @Select("select type from book where id=#{bookId}")
    List<String> getBook(int bookId);

    @Select("select type from book_type where book_id=#{bookId}")
    List<String> getBookType1(List<Integer> bookId);

    int setBookType(@Param("id") int id, @Param("types") List<String> types);

    @Insert("insert into book (id,name,price,is_free,cover) values(#{bookId},#{name},#{price},#{isFree},#{cover})")
    int BookInsert(Book book );


    @Delete("delete from book_type where book_id=#{bookId}")
    int deleteBookTypeByBookId(@Param("bookId") int bookId);

    @Select("select book_id from book_type where type=#{type}")
    List<Integer> selectByType(String type);

    @Select("select id from book where name=#{name}")
    int selectByName(String name);

    @Select("select * from book where id in (select book_id from book_type where type like #{type}) limit #{start},#{size}")
    List<Book> getBookByType(String type, int start, int size);

}
